package com.jeeplus.modules.guide.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.database.datasource.annotation.DS;
import com.jeeplus.modules.guide.entity.MobileAreaChars;
import com.jeeplus.modules.guide.entity.MobileAreaType;
import com.jeeplus.modules.guide.entity.MobileOrgrize;
import com.jeeplus.modules.guide.mapper.MobileBusinessMapper;
import com.jeeplus.modules.guide.task.Send;
import com.jeeplus.modules.guide.utils.MobileBean;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@DS("queuing")
@Service
@RequiredArgsConstructor
@Slf4j
@Transactional(readOnly = true)
public class MobileBusinessService {

    private final MobileBusinessMapper mobilebusinessmapper;

    public List<Map<String,String>> listAreaPoint(){
        return mobilebusinessmapper.listAreaPoint();
    }

    public MobileBean<MobileAreaChars> listTypeName(String areaId, String isTop, String pageNo, String pageSize){
        MobileBean<MobileAreaChars> pageBean = new MobileBean<>();
        PageHelper.startPage(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        List<MobileAreaChars> list = mobilebusinessmapper.listTypeName(areaId,isTop);
        for(MobileAreaChars m : list){
            if(null != m.getTypeName() && m.getTypeName().indexOf("预约") >= 0){
                m.setIsYY("true");
            }
        }
        PageInfo<MobileAreaChars> pageInfo=new PageInfo<>(list);
        pageBean.setCrurentNum(Integer.parseInt(pageNo));
        pageBean.setPageSize(Integer.parseInt(pageSize));
        pageBean.setTotalNum((int) pageInfo.getTotal());
        pageBean.setTotalPageSize(pageInfo.getPages());
        pageBean.setDatas(pageInfo.getList());
        return pageBean;
    }

    public MobileBean<MobileAreaType> findAddrList(String orgrizeStatusValue, String pageNo, String pageSize){
        MobileBean<MobileAreaType> pageBean = new MobileBean<>();
        PageHelper.startPage(Integer.parseInt(pageNo), Integer.parseInt(pageSize));
        PageHelper.orderBy(" orgrizeStatus asc, sort asc");
        List<MobileAreaType> list;
        if(StringUtils.isNotBlank(orgrizeStatusValue)){
            list = mobilebusinessmapper.findAddrList(orgrizeStatusValue.split(","));
        }else{
            list =  mobilebusinessmapper.findAddrList(null);
        }
        PageInfo<MobileAreaType> pageInfo=new PageInfo<>(list);
        pageBean.setCrurentNum(Integer.parseInt(pageNo));
        pageBean.setPageSize(Integer.parseInt(pageSize));
        pageBean.setTotalNum((int) pageInfo.getTotal());
        pageBean.setTotalPageSize(pageInfo.getPages());
        pageBean.setDatas(pageInfo.getList());
        return pageBean;
    }

    public List<MobileOrgrize> listAreaType(){
        return mobilebusinessmapper.listAreaType();
    }

    public String getAreaName(String areaId){
        return mobilebusinessmapper.getAreaName(areaId);
    }

    public String findPid(@Param("areaId")String areaId){
        return mobilebusinessmapper.findPid(areaId);
    }

    public Integer findTypeNum(@Param("areaId")String areaId){
        return mobilebusinessmapper.findTypeNum(areaId);
    }

    public String findTypeNameValue(String areaId,String number){
        return mobilebusinessmapper.findTypeNameValue(areaId,number);
    }
    public Map<String,String> findTypeNameValuePC(String areaId,String number){
        return mobilebusinessmapper.findTypeNameValuePC(areaId,number);
    }
    public String findTypeNameValueById(String id){
        return mobilebusinessmapper.findTypeNameValueById(id);
    }


    public String findPJWXID(String areaId,String number){
        return mobilebusinessmapper.findPJWXID(areaId,number);
    }


    public List<HashMap<String,String>> findUserSMSPJ(){
        return mobilebusinessmapper.findUserSMSPJ();
    }

    @Transactional(readOnly = false)
    public void updateUserSMSPJ(String id){
        mobilebusinessmapper.updateUserSMSPJ(id);
    }

    @Transactional(readOnly = false)
    public int insertUserSMSPJ(int pj,String result,String id){
        return mobilebusinessmapper.insertUserSMSPJ(pj+"",result,id);
    }
    public String checkUserPJ(String id){
        return mobilebusinessmapper.checkUserPJ(id);
    }
    public String findNumberId(String areaId,String number){
        return mobilebusinessmapper.findNumberId(areaId,number);
    }
    @Transactional(readOnly = false)
    public void updatePJValue(String areaId,String number,int pj){
        mobilebusinessmapper.updatePJValue(areaId,number,pj);
    }

    public String findHqueueId(String areaId,String number){
        return mobilebusinessmapper.findHqueueId(areaId,number);
    }
    public HashMap<String,String> findUserValueByHqueueId(String id){
        return mobilebusinessmapper.findUserValueByHqueueId(id);
    }

    public String checkUserPJPC(String areaId,String number){
        return mobilebusinessmapper.checkUserPJPC(areaId,number);
    }
}
